export default {
    data() {
        return {
            token: '',
            getItemTypes: [
                {value: 'All', type: this.$t('type_all_title')}, //全部
                {value: 'selfstudy', type: this.$t('cos_type_selfstudy')}, //网上课程
                {value: 'classroom', type: this.$t('cos_type_classroom')}, //面授课程
                {value: 'audiovideo', type: this.$t('find_open_course')}, //公开课
                {value: 'INTEGRATED', type: this.$t('cos_type_integrated')} //项目于式培训
            ],
            appStatus: [
                {value: 'All', type: this.$t('type_all_title')}, //全部
                {value: 'I', type: this.$t('cos_app_inprogress')}, //进行中
                {value: 'C', type: this.$t('cos_app_completed')}, //已完成
                {value: 'notIAndC', type: this.$t('cos_other')} //其他
            ],
            /*是否是闯关模式*/
            intrudeType: {
                1: this.$t('study_map_intrude'),
                0: this.$t('study_map_no_intrude')
            },
            // 搜索相关类型
            searchType: [
                // (统一为“用户，课程，知识库，游戏课程，专题培训，工作圈，问答”）
                { name: this.$t('type_all_title'), type: 'ALL' }, // 全部
                { name: this.$t('menu_course'), type: 'COURSE' }, // 课程
                { name: this.$t('personal_ls_knowledge'), type: 'KNOWLEDGE' }, // 知识
                // { name: this.$t('find_information'), type: 'ARTICLE' }, // 资讯
                { name: this.$t('personal_ls_knowque'), type: 'QUESTION' }, // 问答
                { name: this.$t('cos_type_map'), type: 'MAP' }, // 游戏课程
                { name: this.$t('konwledge_special_title'), type: 'SUBJECT' }, // 专题培训
                { name: this.$t('personal_user'), type: 'USER' }, // 用户
                { name: this.$t('home_title_6'), type: 'WORK' } // 工作圈
                // { name: this.$t('find_announce'), type: 'BULLETIN' } // 公告
            ],
            recommendTypes: [
                {value: 'All', type: this.$t('type_all_title')}, //全部
                {value: 'tadm', type: this.$t('cos_recommend_tadm_select')}, //培训部
                {value: 'grade', type: this.$t('cos_recommend_grade_select')}, //职级
                {value: 'sup', type: this.$t('cos_recommend_sup_select')}, //上司
                {value: 'position', type: this.$t('cos_recommend_position_select')} //岗位
            ],
            compulsoryTypes: [
                {value: 'All', type: this.$t('type_all_title')}, //全部
                {value: '1', type: this.$t('cos_required')}, //必修
                {value: '0', type: this.$t('cos_elective')} //选修
            ],
            starLevelType: {
                J: this.$t('instructor_level_J'), //'荣誉讲师'
                M: this.$t('instructor_level_M'), //'三级讲师'
                S: this.$t('instructor_level_S'), //'二级讲师'
                D: this.$t('instructor_level_D') //'一级讲师'
            },
            examTypes: [
                {value: 'All', type: this.$t('type_all_title')}, //全部
                {value: 'selfstudy', type: this.$t('exam_type_selfstudy')}, //网上考试
                {value: 'classroom', type: this.$t('exam_type_classroom')} //离线考试
            ],
            courseType: { //课程类型
                SELFSTUDY: this.$t('cos_type_selfstudy'), //网上课程
                CLASSROOM: this.$t('cos_type_classroom'), //面授课程
                INTEGRATED: this.$t('cos_type_integrated'), //项目式培训
                AUDIOVIDEO: this.$t('new_open_course'), //公开课
                SIMPLE: this.$t('cos_type_simple'), //简易课程
                NORMAL: this.$t('cos_type_step'), //课前中后课程
                MAP: this.$t('cos_type_map') //学习地图
            },
            circleType: {
                TOPIC: this.$t('circle259'),
                KNOWLEDGE: this.$t('circle260'),
                ATLAS: this.$t('circle261'),
                ACTIVITY: this.$t('circle262'),
                VOTE: this.$t('circle253'),
                MEMBER: this.$t('circle263')
            },
            freshCourseType: {
                ON_LINE_COURSE: this.$t('cos_type_selfstudy'), //网上课程
                OPEN_COURSE: this.$t('new_open_course'), // 公开课
                CLASSROOM: this.$t('cos_type_classroom'), //面授课程
                INTEGRATED_COURSE: this.$t('cos_type_integrated'),
                MAP: this.$t('cos_type_map'), //学习地图
                AUDIOVIDEO: this.$t('cos_type_video') //视频站
            },
            freshExamType: {
                EXAM_COURSE: this.$t('exam_type_selfstudy'), //在线考试
                OFF_EXAM_COURSE: this.$t('exam_type_classroom') //离线考试
            },
            examType: { //考试类型
                SELFSTUDY: this.$t('exam_type_selfstudy'), //网上考试
                CLASSROOM: this.$t('exam_type_classroom') //离线考试
            },
            historyFrom: {} // 历史from
        };
    },
    methods: {
        getItemType(type, isExam) {
            return isExam ? this.examType[type] : this.courseType[type];
        },
        beforeunloadHandler() {
            localStorage.setItem('isBeforeUnload', true);
        },
        unloadHandler() {
            if (localStorage.getItem('isBeforeUnload')) {
                localStorage.removeItem('isBeforeUnload');
                localStorage.setItem('pageIsFresh', true);
            }
        },
        // 统一返回上一层页面
        goBackCommon() {
            this.$router.go(-1);
        }
    },
    beforeRouteEnter(to, from, next) {
        next(vm => {
            vm.historyFrom = from;
            if (to.query.from === 'OA') {
                localStorage.setItem('isFormOa', true);
            }
            window.addEventListener('beforeunload', vm.beforeunloadHandler);
            window.addEventListener('unload', vm.unloadHandler);
            if (localStorage.getItem('pageIsFresh') && localStorage.getItem('historyFrom')) {
                vm.historyFrom = JSON.parse(localStorage.getItem('historyFrom'));
                localStorage.removeItem('pageIsFresh');
            }
        });
    },
    destroyed() {
        window.removeEventListener('beforeunload', this.beforeunloadHandler);
        window.removeEventListener('unload', this.unloadHandler);
    },
    deactivated() {
        window.removeEventListener('beforeunload', this.beforeunloadHandler);
        window.removeEventListener('unload', this.unloadHandler);
    }
};
